package data

import (
	"bufio"
	"os"
	"strconv"
	"strings"
)

func GetColorMap(filepath string) [][]int {
	file, err := os.Open(filepath)
	if err != nil {
		panic(err)
	}
	reader := bufio.NewReader(file)
	var result [][]int
	for {
		line, _, err := reader.ReadLine()
		if err != nil || bufio.ErrFinalToken == err {
			break
		}
		lineStr := string(line)
		if strings.HasPrefix(lineStr, "#") {
			continue
		}
		ss := strings.Split(lineStr, " ")
		if len(ss) < 2 {
			continue
		}
		var one []int
		one = append(one, getInt(ss[0]))
		colorStr := ss[1]
		if ss[1] == "BEGIN" {
			colorStr = ss[2]
		}
		colors := strings.Split(colorStr, "/")
		one = append(one, getInt(colors[0]))
		one = append(one, getInt(colors[1]))
		one = append(one, getInt(colors[2]))
		result = append(result, one)
	}
	return result
}
func getInt(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}
